home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5264 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  68 lines

  1. Path: lrz-muenchen.de!news
  2. From: watzka@stat.uni-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: gets(rec->num); I don't know what I am doing wrong...
  5. Date: 9 Feb 1996 12:39:04 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4fff98$fv0@sparcserver.lrz-muenchen.de>
  9. References: <4fempt$mjg@aphex.direct.ca>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. etoivane@direct.ca (Ed Toivanen) writes:
  13.  
  14. >I posted the code that I wrote so far.  I can't make gets(rec->id); work 
  15. >properly,  I get 6 or 7 compilation errors indicating that parameter 1
  16. >does not 
  17. >match function prototype.  Each gets() call is incorrect! What to do? 
  18.  
  19. [some definitions edited]
  20.  
  21. >typedef struct student_record{
  22. >    int id;                     /* Range: 1..99, Unique */
  23. >    char name[NAME_LEN + 1];    /* Non-unique */
  24. >    PROGRAM major;
  25. >    MARK marks;
  26. >} STUDENT_RECORD;
  27.  
  28. [some prototypes edited]
  29.  
  30. >int main(void){
  31. >    char studentList[8 + 1];
  32. >    FILE * filePtr;
  33.  
  34. >    printf("Enter database file to open\n");
  35. >    while(!gets(studentList))
  36. >        {}
  37.  
  38. You should not get a diagnostic for this call to gets(), and you 
  39. should not use gets(), but that is a completely different topic.
  40.  
  41. >    
  42. >    if(!initList(studentList, filePtr)){
  43. >        return(1);
  44. >    }
  45.  
  46. >    return(0);
  47. >}    
  48.  
  49. >bool addRecord(FILE* fp, STUDENT_RECORD* rec){
  50. >    printf("Student id\n");
  51. >    gets(rec->id);
  52. >
  53.  
  54. gets() expects a pointer to char, doesn't it? Hint: gets() is _not_
  55. the same as readln() in a completly different language.
  56.     
  57. >    printf("Student's last name first\n");
  58. >    gets(rec->name);       
  59.  
  60. This call to gets() should not produce a diagnostic, because this
  61. time you pass an argument that has the expected type.
  62.  
  63. Kurt
  64. --
  65. | Kurt Watzka                             Phone : +49-89-2180-6254
  66. | watzka@stat.uni-muenchen.de
  67. | ua302aa@sunmail.lrz-muenchen.de
  68.